package cmdb_blacklist_ignore_v1

import (
	"context"

	cmdb_blacklist_rpc "dfx_cmdb/cmdb-blacklist-rpc/types/cmdb-blacklist-rpc"
	"dfx_cmdb/cmdb-gateway/internal/svc"
	"dfx_cmdb/cmdb-gateway/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type InsertIgnoreRuleLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewInsertIgnoreRuleLogic(ctx context.Context, svcCtx *svc.ServiceContext) *InsertIgnoreRuleLogic {
	return &InsertIgnoreRuleLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *InsertIgnoreRuleLogic) InsertIgnoreRule(req *types.InsertIgnoreRuleRequest) (resp *types.PublicResponse, err error) {
	// 调用 RPC 服务插入忽略规则
	grpcReq := &cmdb_blacklist_rpc.InsertIgnoreRuleRequest{
		IgnoreType: req.IgnoreType,
		IgnoreVal:  req.IgnoreVal,
		Enabled:    req.Enabled,
	}
	grpcResp, err := l.svcCtx.IgnoreRuleOperation.InsertIgnoreRule(l.ctx, grpcReq)
	if err != nil {
		return nil, err
	}

	return &types.PublicResponse{
		Message: grpcResp.Message,
	}, nil
}
